
console.log("====== 内容过滤稳定版脚本已部署，等待最终目标... ======");
Java.perform(function() {
    console.log("====== Java.perform() 已执行，Hook 已就位。 ======");
    const SsResponse = Java.use("X.DBo");
    const targetKeyword = '"aweme_list"';

    SsResponse.LIZLLL.implementation = function(responseBody, rawResponse) {
        const result = this.LIZLLL(responseBody, rawResponse);

        try {
            let responseString = null;
            if (rawResponse) {
                try {
                    const body = rawResponse.body();
                    if (body) {
                        const source = body.source();
                        source.request(java.lang.Long.MAX_VALUE); // 请求缓冲整个响应体
                        const buffer = source.buffer();
                        responseString = buffer.clone().readUtf8(); // 从克隆的缓冲区读取，不影响原始数据流
                    }
                } catch (e) {
                    // 如果上述方法失败，则回退到检查 responseBody 本身是否为字符串
                    if (responseBody && responseBody.getClass().getName() === 'java.lang.String') {
                        responseString = responseBody.toString();
                    }
                }
            } else if (responseBody && responseBody.getClass().getName() === 'java.lang.String') {
                responseString = responseBody.toString();
            }

            // 步骤 2: 对获取到的字符串进行内容过滤
            if (responseString && responseString.includes(targetKeyword)) {

                // 步骤 3: 确认找到目标，并使用你指定的格式进行打印
                console.log("\n\n\n" + "===================  TARGET FOUND BY CONTENT  ===================");

                let url = "[URL not found or failed to read]";
                if (rawResponse && rawResponse.LIZ && rawResponse.LIZ.value) {
                    url = rawResponse.LIZ.value.toString();
                }
                console.log("[*] URL (if available): " + url);
                console.log("------------------------------------------------------");
                console.log("[+] Response Body (Formatted):");

                // 尝试美化打印 JSON，如果失败则直接打印原始字符串
                try {
                    const parsedJson = JSON.parse(responseString);
                    console.log(JSON.stringify(parsedJson, null, 2));
                } catch (formatError) {
                    console.log(responseString);
                }

                console.log("===============================================================\n\n\n");
            }

        } catch (e) {
            console.error("[!] Hook 逻辑执行出错: " + e.stack);
        }

        return result;
    };

    console.log("[*] 最终稳定版 Hook 已激活: X.DBo.LIZLLL");
    console.log(`[*] 正在通过内容 \"${targetKeyword}\" 监听所有请求...`);
});


